<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">

    <link rel="stylesheet" href="../bootstrap-3.3.4/dist/css/bootstrap.min.css"/>
    <link rel="stylesheet" href="../Flat-UI-master/dist/css/flat-ui.min.css"/>
    <script src="../Flat-UI-master/dist/js/vendor/jquery.min.js"></script>
    <script src="../bootstrap-3.3.4/dist/js/bootstrap.min.js"></script>
    <script src="../Flat-UI-master/dist/js/flat-ui.min.js"></script>
    <title></title>
    <style>
        .row{
            margin-left: 20px;
            margin-right: 20px;;
        }
        .center{
            text-align: center;
        }
    </style>
    <script src="../js/jquery-3.2.1.min.js"></script>
</head>
<body>

<!-- Static navbar -->
<div class="navbar navbar-default navbar-static-top" role="navigation">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                <span class="sr-only">这什么东西</span>
            </button>
            <a class="navbar-brand" href="Index.html">图书商城</a>
        </div>
        <div class="navbar-collapse collapse">
            <ul class="nav navbar-nav">
                <li class="active"><a href="Index.html">首页</a></li>
                <li><a href="Order.html">我的订单</a></li>
                <li><a href="UserInfo.html">个人中心</a></li>
                <li hidden><a href="FriendLink.html">友情链接</a></li>
            </ul>
            <ul class="nav navbar-nav navbar-right hidden-sm">
                <li><a href="Login.html">登录</a></li>
                <li><a href="Register.html">注册</a></li>
                <li><a id="out">退出</a></li>
                <li>
                    <a href="Cart.html"><span class="glyphicon glyphicon-shopping-cart">购物车</span></a></li>
            </ul>
        </div><!--/.nav-collapse -->
    </div>
</div>

<!--content-->
<div class="row thumbnail">
    <div class="col-sm-4">
            <img style="width: 100%; height: 500px; display: block;" src=""  data-holder-rendered="true">
            <div class="caption center">
                <h3 id="bname"></h3>
                <p id="author"></p>
                <p id="price"></p>
                <!--<a class="btn btn-primary btn-block" role="button" id="buy">立即购买</a>-->
                <p> <a class="btn btn-default btn-block" role="button" id="car">加入购物车</a></p>
                <span id="span"></span>
            </div>
    </div>
    <div class="col-sm-8">
        <div class="caption">
                <h3>图书介绍</h3>
                <p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p>

            </div>

    </div>

</div>

<!--footer-->
<div class="navbar navbar-default navbar-static-bottom">
    版权声明区
</div>
<script>
    function getUrlParameter(name){
        name = name.replace(/[]/,"\[").replace(/[]/,"\[").replace(/[]/,"\\\]");
        var regexS = "[\\?&]"+name+"=([^&#]*)";
        var regex = new RegExp( regexS );
        var results = regex.exec(window.parent.location.href );
        if( results == null ) return ""; else {
            return results[1];
        }
    };
    var bid = getUrlParameter("bid");
    window.onload=function () {
        $.ajax({
            url:"/bookanduser",
            type:"get",
            data:{
                bid:bid
            },
            success:function (re) {
                console.log(re);
                $("#bname").html(re.data.bname);
                $("#author").html(re.data.author);
                $("#price").html(re.data.price);
                $("img").attr("src",re.data.image);
            }
        })
    };
    $("#car").click(function () {
        $.ajax({
            url:"/addcar",
            type:"get",
            data:{
                bid:bid
            },
            success:function (re) {
                console.log(re);
                if(re.code==1002){
                    // alert(re.msg);
                    $("#span").html(re.msg)
                    location.href="/Home/Login.html";
                }else if (re.code == 1001) {
                    // alert(re.msg)
                    $("#span").html(re.msg)
                    console.log(re.msg)
                }else if (re.code == 1000) {
                    location.href="/Home/Cart.html";
                }
            }
        })
    })
    $("#out").click(function () {
        $.ajax({
            url:"/out",
            type:"get",
            success:function (re) {
                if (re.code == 1000) {
                    location.href="/Home/Login.html"
                }
            }
        })
    })
</script>
</body>
</html>